/*
 * $Id$
 */
package se.combitech.combiorder.controller;

import java.io.Serializable;

import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

@ConversationScoped
@Named
public class MenuController implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Inject
    private Conversation conversation;

    
    
    public enum Form{
        HOME,CUSTOMER,ORDER,PRODUCT
    }
    
    private Form selectedForm = Form.HOME;
    
    public Form getSelectedForm() {
        return selectedForm;
    }

    public void setSelectedForm(Form selectedForm) {
        this.selectedForm = selectedForm;
    }

    public String home(){
        setSelectedForm(Form.HOME);
        return "home";
    }
    
    public String regCustomer(){
        setSelectedForm(Form.CUSTOMER);
        beginConversation();
        return "regCustomer";
    }

    public String regOrder(){
        setSelectedForm(Form.ORDER);
        beginConversation();
        return "regOrder";
    }

    public String regProduct(){
        setSelectedForm(Form.PRODUCT);
        beginConversation();
        return "regProduct";
    }
    
    
    private void beginConversation() {
        if (conversation.isTransient()) {
            conversation.begin();

            return;
        }
    }

    private void endConversation() {
        if (!conversation.isTransient()) {
            conversation.end();

            return;
        }
    }

}
